package com.fap.core.bo.meta;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

import com.fap.core.bo.define.BoDefine;
import com.fap.core.bo.define.FieldDefine;

public class BoMeta {

	private String id;
	private String name;
	private String tableName;
	private String tag;
	private String primaryField;
	private boolean isPrivilegeDimension=false;
	private boolean isUsed;
	
	private BoDefine _define;
	private FieldMeta[] _fieldMetas;
	private String[] _fields;
	
	public BoMeta(BoDefine define){
		this._define = define;
		registerFieldMeta();
	}
	
	public String getId() {
		return _define.getId();
	}

	public String getName() {
		return _define.getName();
	}

	public String getTableName() {
		return _define.getTableName();
	}

	public String getTag() {
		return _define.getTag();
	}

	public String getPrimaryField() {
		return _define.getPrimaryField();
	}

	public boolean isPrivilegeDimension() {
		return _define.getIsPrivilegeDimension().equals("1")?true:false;
	}

	public boolean isUsed() {
		return _define.getIsUsed().equals("1")?true:false;
	}

	public FieldMeta[] getFieldMetas(){
		return _fieldMetas;
	}
	
	public String[] getFields(){
		return _fields;
	}
	
	public FieldMeta getFieldMeta(String field){
		for(FieldMeta fm: _fieldMetas){
			if(fm.getFieldName().equals(field))
				return fm;
		}
		return null;
	}
	
	private void registerFieldMeta(){
		List<FieldDefine> fds = _define.getFieldDefines();
		System.out.println("field count:"+fds.size());
		_fieldMetas = new FieldMeta[fds.size()];
		_fields = new String[fds.size()];
		int i=0;
		for(FieldDefine field: fds){
//			System.out.println(field.getId());
//			System.out.println(field.getName());
//			System.out.println(field.getTag());
//			System.out.println(field.getFieldName());
//			System.out.println(field.getKind());
//			System.out.println(field.getDataType());
//			System.out.println(field.getAllowNull());
//			System.out.println(field.getDefaultData());
//			System.out.println(field.getLength());
//			System.out.println(field.getIsUsed());
//			System.out.println(field.getLinkBoId());
//			System.out.println(field.getSubBoId());
//			System.out.println(field.getVerifyRule());
//			System.out.println(field.getVerifyValue());
			
			_fieldMetas[i] = new FieldMeta(field);
			_fields[i] = field.getFieldName();
			i++;
		}
	}
}
